package heven.holt.library.extensions

import android.app.Activity
import heven.holt.library.listener.OnSoftInputChangedListener

fun getTopActivity(): Activity? {
    for (position in activityList.lastIndex downTo 0) {
        val activity = activityList[position]
        if (!activity.isActive()) {
            continue
        }
        return activity
    }
    return null
}

/**
 * 判断Activity是否是活跃状态
 */
fun Activity?.isActive() =
    this != null && !isFinishing && !isDestroyed

fun Activity.registerSoftInputChangedListener(listener: OnSoftInputChangedListener) {
    window.registerSoftInputChangedListener(listener)
}

fun Activity.unregisterSoftInputChangedListener() {
    window.unregisterSoftInputChangedListener()
}